<template>
    <div>
        <Menu active-name="1" mode="horizontal" theme="dark">
            <Submenu name="phone">
                <template slot="title">
                    <Icon type="ios-stats"/>
                    终端管理
                </template>
                <MenuGroup title="手机">
                    <MenuItem name="scanning" to="/DeviceScan">添加手机</MenuItem>
                    <MenuItem name="list-data" to="/DeviceList">手机设置</MenuItem>
                </MenuGroup>
            </Submenu>
            <Submenu name="content">
                <template slot="title">
                    <Icon type="ios-stats"/>
                    内容
                </template>
                <MenuGroup title="内容设置">
                    <MenuItem name="ContentCategory" to="/ContentCategory">分类管理</MenuItem>
                    <MenuItem name="Content" to="/Content">内容管理</MenuItem>
                </MenuGroup>
                <MenuGroup title="模板">
                    <MenuItem name="ContentTemplate" to="/">模板管理</MenuItem>
                </MenuGroup>
            </Submenu>
            <Submenu name="pull">
                <template slot="title">
                    <Icon type="ios-stats"/>
                    发布操作
                </template>
                <MenuGroup title="App和内容">
                    <MenuItem name="ApplicationList" to="/ApplicationList">App</MenuItem>
                    <MenuItem name="pullRadio" to="/DeviceList">模板</MenuItem>
                </MenuGroup>
                <MenuGroup title="图片/视频">
                    <MenuItem name="pullPicture" to="/PullPicture">发布图片</MenuItem>
                    <MenuItem name="pullRadio" to="/DeviceList">发布视频</MenuItem>
                </MenuGroup>
            </Submenu>
            <MenuItem name="setting" to="/Setting">
                <Icon type="ios-paper"/>
                参数设置
            </MenuItem>
        </Menu>
    </div>
</template>

<script>
let process = require('child_process')
let Datastore = require('nedb')
// 实例化连接对象（不带参数默认为内存数据库）
// let db = new Datastore();
let db = new Datastore({
    filename: '/src/render/data/info.db',
    autoload: true
})
export default {
    name: 'ItemTool',
    data () {
        return {
            modal1: false,
            phoneInfo: {
                name: '',
                ip: '',
                device: ''
            },
            errorMessage: ''
        }
    },
    methods: {
        toUser () {
            this.$router.push('/user')
        },
        ok () {
            let createTime = new Date()
            let that = this
            console.log(this.phoneInfo)
            this.$Message.info('Clicked ok')// 插入单项
            db.insert({
                name: that.phoneInfo.name,
                ip: that.phoneInfo.ip,
                device: that.phoneInfo.device,
                createTime: createTime.now
                // eslint-disable-next-line handle-callback-err
            }, (err, ret) => {
                if (!err) {
                    that.$Message.info('保存成功')
                }
            })
        },
        cancel () {
            this.$Message.info('Clicked cancel')
        },
        beginScan () {
            this.doCMD()
        },
        doCMD () {
            let newStdout = []
            process.exec('adb devices', function (error, stdout, stderr) {
                if (stdout) {
                    newStdout = stdout.split('\n')
                    let newStr = newStdout[1].replace(/[\r\n]*/g, '')
                    if (newStr != '') {
                        let deviceArr = newStr.split('')
                        if (deviceArr[0] != '') {

                        }
                    } else {
                        console.log(false)
                    }
                }
            })
        },
    }
}
</script>

<style scoped>

</style>
